package org.shj.pattern.observe

abstract class Observer {
  
  def update()
  
  def subscribe(subj: Subject){
    subj.addObserver(this)
  }
}

class GaoShou extends Observer{
  var stock: Stock = _
  
  def subscribe(stock: Stock){
    this.stock = stock
    super.subscribe(stock)
  }
  
  def update(){
    println(s"买进股票。价格： ${stock.getPrice()}")
  }
}

class JiuCai extends Observer{
  var stock: Stock = _
  
  def subscribe(stock: Stock){
    this.stock = stock
    super.subscribe(stock)
  }
  
  def update(){
    println(s"卖出股票。价格： ${stock.getPrice()}")
  }
}